home *** CD-ROM | disk | FTP | other *** search
/ PCMania 56 / PCMania CD56_1.iso / abc.z / EXCELDAT.FRM < prev    next >
Text File  |  1996-12-16  |  12KB  |  410 lines

  1. VERSION 4.00
  2. Begin VB.Form ExcelSample 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Excel Data DEMO"
  7.    ClientHeight    =   4125
  8.    ClientLeft      =   3480
  9.    ClientTop       =   1800
  10.    ClientWidth     =   4815
  11.    BeginProperty Font 
  12.       name            =   "MS Sans Serif"
  13.       charset         =   0
  14.       weight          =   700
  15.       size            =   8.25
  16.       underline       =   0   'False
  17.       italic          =   0   'False
  18.       strikethrough   =   0   'False
  19.    EndProperty
  20.    ForeColor       =   &H80000008&
  21.    Height          =   4815
  22.    Icon            =   "EXCELDAT.frx":0000
  23.    Left            =   3420
  24.    LinkTopic       =   "Form1"
  25.    ScaleHeight     =   4125
  26.    ScaleWidth      =   4815
  27.    Top             =   1170
  28.    Width           =   4935
  29.    Begin VB.CommandButton ReadData 
  30.       Appearance      =   0  'Flat
  31.       BackColor       =   &H80000005&
  32.       Caption         =   "&Read Data"
  33.       Height          =   375
  34.       Left            =   3360
  35.       TabIndex        =   8
  36.       Top             =   3120
  37.       Width           =   1215
  38.    End
  39.    Begin VB.ListBox ExcelFields 
  40.       Appearance      =   0  'Flat
  41.       Height          =   1590
  42.       Left            =   360
  43.       MultiSelect     =   2  'Extended
  44.       TabIndex        =   3
  45.       TabStop         =   0   'False
  46.       Top             =   1560
  47.       Width           =   2655
  48.    End
  49.    Begin VB.CommandButton Browse 
  50.       Appearance      =   0  'Flat
  51.       BackColor       =   &H80000005&
  52.       Caption         =   "&Browse..."
  53.       Height          =   375
  54.       Left            =   3240
  55.       TabIndex        =   2
  56.       Top             =   600
  57.       Width           =   1215
  58.    End
  59.    Begin VB.CommandButton Quit 
  60.       Appearance      =   0  'Flat
  61.       BackColor       =   &H80000005&
  62.       Cancel          =   -1  'True
  63.       Caption         =   "&Quit"
  64.       Height          =   375
  65.       Left            =   3360
  66.       TabIndex        =   1
  67.       Top             =   1320
  68.       Width           =   1215
  69.    End
  70.    Begin VB.CommandButton MakeChart 
  71.       Appearance      =   0  'Flat
  72.       BackColor       =   &H80000005&
  73.       Caption         =   "Make &Chart"
  74.       Default         =   -1  'True
  75.       Enabled         =   0   'False
  76.       Height          =   375
  77.       Left            =   3360
  78.       TabIndex        =   0
  79.       Top             =   3600
  80.       Width           =   1215
  81.    End
  82.    Begin VB.Frame Frame1 
  83.       Appearance      =   0  'Flat
  84.       BackColor       =   &H00C0C0C0&
  85.       Caption         =   "Source Excel Data File"
  86.       ForeColor       =   &H80000008&
  87.       Height          =   975
  88.       Left            =   240
  89.       TabIndex        =   4
  90.       Top             =   120
  91.       Width           =   4335
  92.       Begin VB.TextBox DataFilename 
  93.          Appearance      =   0  'Flat
  94.          Height          =   300
  95.          Left            =   120
  96.          TabIndex        =   5
  97.          Text            =   "DataFilename"
  98.          Top             =   510
  99.          Width           =   2715
  100.       End
  101.    End
  102.    Begin VB.Frame Frame2 
  103.       Appearance      =   0  'Flat
  104.       BackColor       =   &H00C0C0C0&
  105.       Caption         =   "Fields"
  106.       ForeColor       =   &H80000008&
  107.       Height          =   2775
  108.       Left            =   240
  109.       TabIndex        =   6
  110.       Top             =   1200
  111.       Width           =   2895
  112.       Begin VB.Label HintText 
  113.          Appearance      =   0  'Flat
  114.          BackColor       =   &H00C0C0C0&
  115.          Caption         =   "To multi-select, click on items in the list while holding the CTRL key."
  116.          ForeColor       =   &H80000008&
  117.          Height          =   615
  118.          Left            =   120
  119.          TabIndex        =   7
  120.          Top             =   2040
  121.          Width           =   2655
  122.       End
  123.    End
  124.    Begin MSComDlg.CommonDialog CMDialog1 
  125.       Left            =   3720
  126.       Top             =   2160
  127.       _Version        =   65536
  128.       _ExtentX        =   847
  129.       _ExtentY        =   847
  130.       _StockProps     =   0
  131.    End
  132.    Begin VB.Menu Help 
  133.       Caption         =   "Help"
  134.       Begin VB.Menu About 
  135.          Caption         =   "About"
  136.       End
  137.    End
  138. End
  139. Attribute VB_Name = "ExcelSample"
  140. Attribute VB_Creatable = False
  141. Attribute VB_Exposed = False
  142. Const xlR1C1 = -4150
  143. Dim TraderData(40, 15) As String
  144. Dim Record_Count As Integer
  145. Dim CreateFailed As Integer
  146. Dim Col As Integer, Row As Integer
  147. Dim ExcelApp As Object
  148.  
  149. Private Sub About_Click()
  150.     Load AboutForm
  151.     AboutForm.Visible = True
  152.     ExcelSample.Enabled = False
  153. End Sub
  154.  
  155. Private Sub Browse_Click()
  156.     On Error GoTo ErrHandler2        'CancelError is True
  157.                                     'Set filters
  158.     CMDialog1.Filter = "Excel Files (*.xls)|*.XLS|Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
  159.     CMDialog1.FilterIndex = 1       'Set default filter
  160.     CMDialog1.Action = 1            'Display the Open dialog box
  161.  
  162.     DataFilename = CMDialog1.filename
  163. ErrHandler2:                         'User pressed Cancel button
  164.     Exit Sub
  165. End Sub
  166.  
  167. Private Sub CreateExcel()
  168.     On Error GoTo ExcelFail
  169.     CreateFailed = False
  170.     Set ExcelApp = CreateObject("Excel.Application")
  171.     Exit Sub
  172.  
  173. ExcelFail:
  174.     Call HourGlassOff
  175.     MsgBox "You must have MS Excel installed to run this DEMO!", 16, "Critical Error"
  176.     CreateFailed = True
  177.     Resume Next
  178.  
  179. End Sub
  180.  
  181. Private Sub DataFilename_Change()
  182.     Call ValidateFilename
  183. End Sub
  184.  
  185. Private Sub Form_Load()
  186.     DataFilename = App.Path + "\ABCSAMPL.XLS"
  187. End Sub
  188.  
  189. Private Sub GetDataFile(DataFile As String)
  190.     Dim ExcelSheet As Object, xlWorkbooks As Object
  191.     Dim Cell As Object
  192.     Dim Rowz As Integer, Colz As Integer
  193.  
  194.     ' Load up Excel - sets ExcelApp Object
  195.     Call CreateExcel
  196.  
  197.     If CreateFailed Then Exit Sub
  198.     
  199.     ExcelApp.Application.Visible = True
  200.     Set xlWorkbooks = ExcelApp.Workbooks
  201.     xlWorkbooks.Open DataFile
  202.     Set ExcelSheet = ExcelApp.ActiveSheet
  203.     ExcelSheet.Activate
  204.     ExcelApp.ReferenceStyle = xlR1C1
  205.     
  206.     ExcelSample.Visible = False
  207.  
  208.     ' Find the first row with data
  209.     ' (check only the first 256 rows)
  210.     For FirstRow = 1 To 256
  211.         Set Cell = ExcelSheet.Cells(FirstRow, 1)
  212.         Cell.Select
  213.         If Not Cell.Value = Empty Then Exit For
  214.     Next FirstRow
  215.  
  216.     ' Find the last row with data
  217.     ' (check only the first 256 rows)
  218.     For Rows = FirstRow To FirstRow + 256
  219.         Set Cell = ExcelSheet.Cells(Rows, 1)
  220.         Cell.Select
  221.         If Cell.Value = Empty Then
  222.             Rows = Rows - FirstRow - 1
  223.             Exit For
  224.         End If
  225.     Next Rows
  226.  
  227.     ' Now count the number of columns
  228.     ' (Again only up to 256)
  229.     For Col = 1 To 256
  230.         Set Cell = ExcelSheet.Cells(FirstRow, Col)
  231.         Cell.Select
  232.         If Cell.Value = Empty Then
  233.             Col = Col - 1
  234.             Exit For
  235.         End If
  236.     Next Col
  237.  
  238.  
  239.     DoEvents
  240.     Call HourGlassOn
  241.     For Rowz = 1 To Rows + 1
  242.         For Colz = 1 To Col
  243.             Set Cell = ExcelSheet.Cells(FirstRow + Rowz - 1, Colz)
  244.             Cell.Select
  245.             TraderData(Rowz, Colz) = Cell.Value
  246.         Next Colz
  247.     Next Rowz
  248.     Call HourGlassOff
  249.     Record_Count = Rows
  250.  
  251.     For Colz = 1 To Col
  252.         ExcelFields.AddItem TraderData(1, Colz)
  253.     Next Colz
  254.  
  255.     ExcelSheet.Application.DisplayAlerts = False
  256.     ExcelSheet.Application.ActiveWorkbook.Close
  257.     ExcelApp.Application.Quit
  258.  
  259.     ExcelSample.Visible = True
  260.     MakeChart.Enabled = True
  261.     Call SelectAll(ExcelFields)
  262.  
  263. End Sub
  264.  
  265. Private Sub GetExcel()
  266.     On Error GoTo TryCreate
  267.  
  268.     Call HourGlassOn
  269.     Set ExcelApp = GetObject(, "Excel.Application")
  270.     Call HourGlassOff
  271.     Exit Sub
  272.  
  273. TryCreate:
  274.     Call CreateExcel
  275.     Resume Next
  276. End Sub
  277.  
  278. Private Sub HourGlassOff()
  279.     Screen.MousePointer = 0
  280. End Sub
  281.  
  282. Private Sub HourGlassOn()
  283.     Screen.MousePointer = 11
  284. End Sub
  285.  
  286. Private Sub MakeChart_Click()
  287. Dim ABC As Object, Chart As Object, Field1 As Object, Field2 As Object
  288. Dim X As Integer, Y As Integer, Index_1 As Integer, ShapeCount As Integer
  289. Dim Line1 As Object, FieldNameIndex As Integer
  290. Static Fields() As Object
  291. Static Shape() As Object
  292.  
  293.     Dim Units as Integer
  294.  
  295.     ' Reset counters for the PercentGauge
  296.     TotalLoops = 3
  297.     CurrentLoop = 0
  298.  
  299.     ReDim Fields(ExcelFields.ListCount)
  300.  
  301.     'Start ABC
  302.     Call HourGlassOn
  303.     Set ABC = CreateObject("ABCFlow.Application")
  304.     ABC.Visible = True
  305.     ABC.FieldViewerVisible = False
  306.     Call HourGlassOff
  307.  
  308.     'Make a new chart
  309.     Set Chart = ABC.New
  310.     Units = Chart.Units ' save current units to restore them later
  311.     Chart.Units = 0     ' set units to inches for all measurements below
  312.     
  313.     'Set up some parameters for chart
  314.     Chart.DrawPositionX = 1
  315.     Chart.DrawSpacingX = 1.5
  316.     Chart.FieldNamesHidden = True
  317.     Chart.NoRepaint = True
  318.  
  319.     Rem Use right angle lines
  320.     Chart.CurrentLineRouting = 1
  321.     
  322.     ABC.Activate         ' Bring FlowCharter to the foreground
  323.     ABC.PercentGauge
  324.     
  325.     'Get the shape count
  326.     ReDim Shape(Record_Count)
  327.     ShapeCount = Record_Count
  328.  
  329.     For X = 1 To ShapeCount
  330.         If ABC.PercentGaugeCancelled Then Exit For
  331.  
  332.         'Draw shapes
  333.         Set Shape(X) = Chart.DrawShape("FlowCharter Palettes\Standard\Operation")
  334.         Shape(X).Shape.FillColor = ABC.Blue
  335.  
  336.         'Create another row of shapes
  337.         If (X Mod 5) = 0 Then
  338.             Chart.DrawPositionX = 1
  339.             Chart.DrawPositionY = Chart.DrawPositionY + 2
  340.         End If
  341.         ABC.PercentGaugeValue = ((X / ShapeCount) * (1 / TotalLoops) + CurrentLoop / TotalLoops) * 100
  342.     Next X
  343.     
  344.     CurrentLoop = CurrentLoop + 1
  345.     'Draw Lines
  346.     For X = 2 To ShapeCount
  347.         If ABC.PercentGaugeCancelled Then Exit For
  348.  
  349.         Set Line1 = Chart.DrawLine(Shape(X), Shape(X - 1))
  350.         Line1.Line_.DestArrowStyle = 0
  351.         ABC.PercentGaugeValue = ((X / ShapeCount) * (1 / TotalLoops) + CurrentLoop / TotalLoops) * 100
  352.     Next X
  353.         
  354.     'Position fields below shapes
  355.     Chart.FieldPlacement = 3
  356.  
  357.     'Add Field Ttemplates to Chart
  358.     For X = 0 To ExcelFields.ListCount - 1
  359.         If ExcelFields.Selected(X) Then
  360.             Set Fields(X) = Chart.FieldTemplates.Add(ExcelFields.List(X))
  361.             'Format field as text
  362.             Fields(X).Format = 0
  363.         End If
  364.     Next X
  365.  
  366.     CurrentLoop = CurrentLoop + 1
  367.     'Put Field data into shapes
  368.     For X = 1 To ShapeCount
  369.         If ABC.PercentGaugeCancelled Then Exit For
  370.         For Y = 1 To Col
  371.             Shape(X).FieldValues.Item(TraderData(1, Y)).Value = TraderData(X + 1, Y)
  372.         Next Y
  373.  
  374.         ABC.PercentGaugeValue = ((X / ShapeCount) * (1 / TotalLoops) + CurrentLoop / TotalLoops) * 100
  375.     Next X
  376.     
  377.     ABC.HidePercentGauge
  378.  
  379.     Chart.Units = Units
  380.     Chart.NoRepaint = False
  381.     Chart.Repaint
  382.  
  383. End Sub
  384.  
  385. Private Sub Quit_Click()
  386.     Unload ExcelSample
  387. End Sub
  388.  
  389. Private Sub ReadData_Click()
  390.     ExcelFields.Clear
  391.     GetDataFile (DataFilename) 'Open the selected file
  392. End Sub
  393.  
  394. Private Sub SelectAll(ListBox As ListBox)
  395.     For it = 0 To ListBox.ListCount - 1
  396.         ListBox.Selected(it) = True
  397.     Next it
  398. End Sub
  399.  
  400. Private Sub ValidateFilename()
  401.    On Error Resume Next
  402.    Attr = GetAttr(DataFilename)
  403.    If Err Then
  404.         ReadData.Enabled = False
  405.    Else
  406.         ReadData.Enabled = True
  407.    End If
  408. End Sub
  409.  
  410.